package com.example.demo.collectionexorection;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @Description Room
 * @Author songchuanlong
 * @Date 2025-05-16
 */
public class Room {
    private List<Card> cards = new ArrayList();

    public Room() {
        String[] point={"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
        String[] color={"♠","♥","♦","♣"};
        String[] W={"🃏","🐕"};
        int size =0;
        for (String p : point) {
            size++;
            for (String c : color) {
                cards.add(new Card(p, c, size));
            }
        }
        //大王
        //小王
        Card card1 = new Card("", "🃏", ++size);
        Card card2 = new Card("", "🐕", ++size);
        Collections.addAll(cards,card1,card2);
        System.out.println(cards);
    }

    public void start() {
        //1、洗牌
        Collections.shuffle(cards);
        System.out.println(cards);
        //2、发牌
        List<Card> playOne = new ArrayList<>();
        List<Card> playTwo = new ArrayList<>();
        List<Card> playThree = new ArrayList<>();
        for (int i = 0; i < cards.size()-3; i++) {
            if(i%3==0){
                playOne.add(cards.get(i));
            }else if (i%3==1){
                playTwo.add(cards.get(i));
            }else {
                playThree.add(cards.get(i));
            }
        }
        List<Card> lastCards = cards.subList(cards.size() - 3, cards.size());
        Collections.sort(lastCards,(Comparator.comparingInt(Card::getSize)));

        //3、对发的牌进行排序
        Collections.sort(playOne,(Comparator.comparingInt(Card::getSize)));
        Collections.sort(playTwo,(Comparator.comparingInt(Card::getSize)));
        Collections.sort(playThree,(Comparator.comparingInt(Card::getSize)));
        System.out.println("玩家一"+playOne);
        System.out.println("玩家二"+playTwo);
        System.out.println("玩家三"+playThree);
        System.out.println("底牌"+lastCards);
        //4、看牌(假设玩家一获得了底牌)
        playTwo.addAll(lastCards);
        Collections.sort(playTwo,(Comparator.comparingInt(Card::getSize)));
        System.out.println("玩家二获得了底牌"+playTwo);
    }
}
